/*
 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION!

import { int32, float32 } from "@koalaui/common"
import { KStringPtr, KBoolean, RuntimeType, runtimeType, isResource, isInstanceOf } from "@koalaui/interop"
import { NodeAttach, remember } from "@koalaui/runtime"
import { ComponentBase } from "./ComponentBase"
import { TypeChecker } from "#components"
import { ArkCommonMethodComponent } from "./ArkCommon"
import { ArkXComponentPeer } from "./peers/ArkXcomponentPeer"
import { UseEventsProperties } from "./use_properties"
import { CommonMethod } from "./ArkCommonInterfaces"
import { XComponentAttribute, OnNativeLoadCallback, XComponentOptions } from "./ArkXcomponentInterfaces"
import { VoidCallback } from "./ArkUnitsInterfaces"
import { Type_XComponentInterface_value } from "./SyntheticDeclarations"
import { XComponentController } from "./ArkXComponentControllerMaterialized"
/** @memo:stable */
export class ArkXComponentComponent extends ArkCommonMethodComponent {
    getPeer(): ArkXComponentPeer {
        return (this.peer as ArkXComponentPeer)
    }
    /** @memo */
    public setXComponentOptions(value: Type_XComponentInterface_value | XComponentOptions): this {
        if (this.checkPriority("setXComponentOptions")) {
            const value_type = runtimeType(value)
            if ((((RuntimeType.OBJECT == value_type)))) {
                const value_casted = value as (Type_XComponentInterface_value)
                this.getPeer()?.setXComponentOptions0Attribute(value_casted)
                return this
            }
            if ((((RuntimeType.OBJECT == value_type)))) {
                const value_casted = value as (Type_XComponentInterface_value)
                this.getPeer()?.setXComponentOptions1Attribute(value_casted)
                return this
            }
            if ((TypeChecker.isXComponentOptions(value, true, true, false))) {
                const options_casted = value as (XComponentOptions)
                this.getPeer()?.setXComponentOptions2Attribute(options_casted)
                return this
            }
            throw new Error("Can not select appropriate overload")
        }
        return this
    }
    /** @memo */
    public onLoad(value: OnNativeLoadCallback): this {
        if (this.checkPriority("onLoad")) {
            const value_casted = value as (OnNativeLoadCallback)
            this.getPeer()?.onLoadAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onDestroy(value: VoidCallback): this {
        if (this.checkPriority("onDestroy")) {
            const value_casted = value as (VoidCallback)
            this.getPeer()?.onDestroyAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public enableAnalyzer(value: boolean): this {
        if (this.checkPriority("enableAnalyzer")) {
            const value_casted = value as (boolean)
            this.getPeer()?.enableAnalyzerAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public enableSecure(value: boolean): this {
        if (this.checkPriority("enableSecure")) {
            const value_casted = value as (boolean)
            this.getPeer()?.enableSecureAttribute(value_casted)
            return this
        }
        return this
    }
    public applyAttributesFinish(): void {
        // we calls this function outside of class, so need to make it public
        super.applyAttributesFinish()
    }
}

/** @memo */
export function ArkXComponent(
  /** @memo */
  style: ((attributes: ArkXComponentComponent) => void) | undefined,
  /** @memo */
  content_: (() => void) | undefined,
  value: Type_XComponentInterface_value | XComponentOptions
) {
    const receiver = remember(() => {
        return new ArkXComponentComponent()
    })
    NodeAttach<ArkXComponentPeer>((): ArkXComponentPeer => ArkXComponentPeer.create(receiver), (_: ArkXComponentPeer) => {
        receiver.setXComponentOptions(value)
        style?.(receiver)
        content_?.()
        receiver.applyAttributesFinish()
    })
}
